<!DOCTYPE html>

<html>
<head>
<meta charset="UTF-8">
<link href="style.css" type="text/css" rel="stylesheet">
<title>VRANGEPD—Range Restriction Calculation For Packed Pairs of Float64 Values </title></head>
<body>
<h1>VRANGEPD—Range Restriction Calculation For Packed Pairs of Float64 Values</h1>
<table>
<tr>
<th>Opcode/Instruction</th>
<th>Op /En</th>
<th>64/32 bit Mode Support</th>
<th>CPUID Feature Flag</th>
<th>Description</th></tr>
<tr>
<td>
<p>EVEX.NDS.128.66.0F3A.W1 50 /r ib</p>
<p>VRANGEPD xmm1 {k1}{z}, xmm2, xmm3/m128/m64bcst, imm8</p></td>
<td>FV</td>
<td>V/V</td>
<td>AVX512VL AVX512DQ</td>
<td>Calculate two RANGE operation output value from 2 pairs of double-precision floating-point values in xmm2 and xmm3/m128/m32bcst, store the results to xmm1 under the writemask k1. Imm8 specifies the comparison and sign of the range operation.</td></tr>
<tr>
<td>
<p>EVEX.NDS.256.66.0F3A.W1 50 /r ib</p>
<p>VRANGEPD ymm1 {k1}{z}, ymm2, ymm3/m256/m64bcst, imm8</p></td>
<td>FV</td>
<td>V/V</td>
<td>AVX512VL AVX512DQ</td>
<td>Calculate four RANGE operation output value from 4pairs of double-precision floating-point values in ymm2 and ymm3/m256/m32bcst, store the results to ymm1 under the writemask k1. Imm8 specifies the comparison and sign of the range operation.</td></tr>
<tr>
<td>
<p>EVEX.NDS.512.66.0F3A.W1 50 /r ib</p>
<p>VRANGEPD zmm1 {k1}{z}, zmm2, zmm3/m512/m64bcst{sae}, imm8</p></td>
<td>FV</td>
<td>V/V</td>
<td>AVX512DQ</td>
<td>Calculate eight RANGE operation output value from 8 pairs of double-precision floating-point values in zmm2 and zmm3/m512/m32bcst, store the results to zmm1 under the writemask k1. Imm8 specifies the comparison and sign of the range operation.</td></tr></table>
<h3>Instruction Operand Encoding</h3>
<table>
<tr>
<td>Op/En</td>
<td>Operand 1</td>
<td>Operand 2</td>
<td>Operand 3</td>
<td>Operand 4</td></tr>
<tr>
<td>FV</td>
<td>ModRM:reg (w)</td>
<td>EVEX.vvvv (r)</td>
<td>ModRM:r/m (r)</td>
<td>Imm8</td></tr></table>
<p><strong>Description</strong></p>
<p>This instruction calculates 2/4/8 range operation outputs from two sets of packed input double-precision FP values in the first source operand (the second operand) and the second source operand (the third operand). The range outputs are written to the destination operand (the first operand) under the writemask k1.</p>
<p>Bits7:4 of imm8 byte must be zero. The range operation output is performed in two parts, each configured by a two-bit control field within imm8[3:0]:</p>
<p>The encodings of Imm8[1:0] and Imm8[3:2] are shown in Figure 5-27.</p>
<table>
<tr>
<td>
<p>7</p>
<p>imm8</p></td>
<td>6</td>
<td>
<p>5</p>
<p>Imm8[3:2] = 00b : Select sign(SRC1)</p>
<p>Imm8[3:2] = 01b : Select sign(Compare_Result)</p>
<p>Imm8[3:2] = 10b : Set sign to 0 </p></td></tr></table></body></html></html><html><body><table><tr><td><p>Imm8[3:2] = 11b : Set sign to 1</p></td>
<td>4</td>
<td>3</td>
<td>2</td>
<td>1</td>
<td>
<p>0</p>
<p>Imm8[1:0] = 00b : Select Min value</p>
<p>Imm8[1:0] = 01b : Select Max value</p>
<p>Imm8[1:0] = 10b : Select Min-Abs value</p>
<p>Imm8[1:0] = 11b : Select Max-Abs value</p></td></tr></table>
<svg width="559.5300075" viewBox="112.440000 1328746.319995 373.020005 13.260005" height="19.8900075001">
<rect y="1328746.5" x="112.98" style="fill:rgba(0,0,0,0);stroke:rgb(0,0,0);stroke-width:1pt;" height="12.8400000001" width="185.4"></rect>
<text y="1328755.0668" x="325.98" style="font-size:6.000000pt" lengthAdjust="spacingAndGlyphs" textLength="41.6532">Sign Control (SC)</text>
<text y="1328755.0668" x="410.52" style="font-size:6.000000pt" lengthAdjust="spacingAndGlyphs" textLength="65.5206">Compare Operation Select</text>
<text y="1328755.0668" x="184.02" style="font-size:6.000000pt" lengthAdjust="spacingAndGlyphs" textLength="33.7884">Must Be Zero</text></svg>
<h3>Figure 5-27.  Imm8 Controls for VRANGEPD/SD/PS/SS</h3>
<p>When one or more of the input value is a NAN, the comparison operation may signal invalid exception (IE). Details with one of more input value is NAN is listed in Table 5-12. If the comparison raises an IE, the sign select control (Imm8[3:2] has no effect to the range operation output, this is indicated also in Table 5-12.</p>
<p>When both input values are zeros of opposite signs, the comparison operation of MIN/MAX in the range compare operation is slightly different from the conceptually similar FP MIN/MAX operation that are found in the instructions VMAXPD/VMINPD. The details of MIN/MAX/MIN_ABS/MAX_ABS operation for VRANGEPD/PS/SD/SS for magni-tude-0, opposite-signed input cases are listed in Table 5-13.</p>
<p>Additionally, non-zero, equal-magnitude with opposite-sign input values perform MIN_ABS or MAX_ABS compar-ison operation with result listed in Table 5-14.</p>
<h3>Table 5-12. Signaling of Comparison Operation of One or More NaN Input Values and Effect of Imm8[3:2]</h3>
<table>
<tr>
<th>Src1</th>
<th>Src2</th>
<th>Result</th>
<th>IE Signaling Due to Comparison</th>
<th>Imm8[3:2] Effect to Range Output</th></tr>
<tr>
<td>sNaN1</td>
<td>sNaN2</td>
<td>Quiet(sNaN1)</td>
<td>Yes</td>
<td>Ignored</td></tr>
<tr>
<td>sNaN1</td>
<td>qNaN2</td>
<td>Quiet(sNaN1)</td>
<td>Yes</td>
<td>Ignored</td></tr>
<tr>
<td>sNaN1</td>
<td>Norm2</td>
<td>Quiet(sNaN1)</td>
<td>Yes</td>
<td>Ignored</td></tr>
<tr>
<td>qNaN1</td>
<td>sNaN2</td>
<td>Quiet(sNaN2)</td>
<td>Yes</td>
<td>Ignored</td></tr>
<tr>
<td>qNaN1</td>
<td>qNaN2</td>
<td>qNaN1</td>
<td>No</td>
<td>Applicable</td></tr>
<tr>
<td>qNaN1</td>
<td>Norm2</td>
<td>Norm2</td>
<td>No</td>
<td>Applicable</td></tr>
<tr>
<td>Norm1</td>
<td>sNaN2</td>
<td>Quiet(sNaN2)</td>
<td>Yes</td>
<td>Ignored</td></tr>
<tr>
<td>Norm1</td>
<td>qNaN2</td>
<td>Norm1</td>
<td>No</td>
<td>Applicable</td></tr></table>
<h3>Table 5-13. Comparison Result for Opposite-Signed Zero Cases for MIN, MIN_ABS and MAX, MAX_ABS</h3>
<table>
<tr>
<td></td>
<th>MIN and MIN_ABS</th>
<td></td>
<td></td>
<th>MAX and MAX_ABS</th>
<td></td></tr>
<tr>
<th>Src1</th>
<th>Src2</th>
<th>Result</th>
<th>Src1</th>
<th>Src2</th>
<th>Result</th></tr>
<tr>
<td>+0</td>
<td>-0</td>
<td>-0</td>
<td>+0</td>
<td>-0</td>
<td>+0</td></tr>
<tr>
<td>-0</td>
<td>+0</td>
<td>-0</td>
<td>-0</td>
<td>+0</td>
<td>+0</td></tr></table>
<h3>Table 5-14. Comparison Result of Equal-Magnitude Input Cases for MIN_ABS and MAX_ABS, (|a| = |b|, a&gt;0, b&lt;0)</h3>
<table>
<tr>
<td></td>
<th>MIN_ABS (|a| = |b|, a&gt;0, b&lt;0)</th>
<td></td>
<td></td>
<th>MAX_ABS (|a| = |b|, a&gt;0, b&lt;0)</th>
<td></td></tr>
<tr>
<th>Src1</th>
<th>Src2</th>
<th>Result</th>
<th>Src1</th>
<th>Src2</th>
<th>Result</th></tr>
<tr>
<td>a</td>
<td>b</td>
<td>b</td>
<td>a</td>
<td>b</td>
<td>a</td></tr>
<tr>
<td>b</td>
<td>a</td>
<td>b</td>
<td>b</td>
<td>a</td>
<td>a</td></tr></table>
<p><strong>Operation</strong></p>
<p>RangeDP(SRC1[63:0], SRC2[63:0], CmpOpCtl[1:0], SignSelCtl[1:0])</p>
<p>{</p>
<p>// Check if SNAN and report IE, see also Table 5-12</p>
<p>IF (SRC1 = SNAN) THEN RETURN (QNAN(SRC1), set IE);</p>
<p>IF (SRC2 = SNAN) THEN RETURN (QNAN(SRC2), set IE);</p>
<p>Src1.exp (cid:197) SRC1[62:52];</p>
<p>Src1.fraction (cid:197) SRC1[51:0];</p>
<p>IF ((Src1.exp = 0 ) and (Src1.fraction != 0)) THEN// Src1 is a denormal number</p>
<p>IF DAZ THEN Src1.fraction (cid:197) 0;</p>
<p>ELSE IF (SRC2 &lt;&gt; QNAN) Set DE; FI;</p>
<p>FI;</p>
<p>Src2.exp (cid:197) SRC2[62:52];</p>
<p>Src2.fraction (cid:197) SRC2[51:0];</p>
<p>IF ((Src2.exp = 0) and (Src2.fraction !=0 )) THEN// Src2 is a denormal number</p>
<p>IF DAZ THEN Src2.fraction (cid:197) 0;</p>
<p>ELSE IF (SRC1 &lt;&gt; QNAN) Set DE; FI;</p>
<p>FI;</p>
<p>IF</p>
<p>(SRC2 = QNAN) THEN{TMP[63:0] (cid:197) SRC1[63:0]}</p>
<p>ELSE IF(SRC1 = QNAN) THEN{TMP[63:0] (cid:197) SRC2[63:0]}</p>
<p>ELSE IF (Both SRC1, SRC2 are magnitude-0 and opposite-signed) TMP[63:0] (cid:197) from Table 5-13</p>
<p>ELSE IF (Both SRC1, SRC2 are magnitude-equal and opposite-signed and CmpOpCtl[1:0] &gt; 01) TMP[63:0] (cid:197) from Table 5-14</p>
<p>ELSE</p>
<p>Case(CmpOpCtl[1:0])</p>
<p>00: TMP[63:0] (cid:197) (SRC1[63:0] ≤ SRC2[63:0]) ? SRC1[63:0] : SRC2[63:0];</p>
<p>01: TMP[63:0] (cid:197) (SRC1[63:0] ≤ SRC2[63:0]) ? SRC2[63:0] : SRC1[63:0];</p>
<p>10: TMP[63:0] (cid:197) (ABS(SRC1[63:0]) ≤ ABS(SRC2[63:0])) ? SRC1[63:0] : SRC2[63:0];</p>
<p>11: TMP[63:0] (cid:197) (ABS(SRC1[63:0]) ≤ ABS(SRC2[63:0])) ? SRC2[63:0] : SRC1[63:0];</p>
<p>ESAC;</p>
<p>FI;</p>
<p>Case(SignSelCtl[1:0])</p>
<p>00: dest (cid:197) (SRC1[63] &lt;&lt; 63) OR (TMP[62:0]);// Preserve Src1 sign bit</p>
<p>01: dest (cid:197) TMP[63:0];// Preserve sign of compare result</p>
<p>10: dest (cid:197) (0 &lt;&lt; 63) OR (TMP[62:0]);// Zero out sign bit</p>
<p>11: dest (cid:197) (1 &lt;&lt; 63) OR (TMP[62:0]);// Set the sign bit</p>
<p>ESAC;</p>
<p>RETURN dest[63:0];</p>
<p>}</p>
<p>CmpOpCtl[1:0]= imm8[1:0]; SignSelCtl[1:0]=imm8[3:2];</p>
<p><strong>VRANGEPD (EVEX encoded versions)</strong></p>
<p>(KL, VL) = (2, 128), (4, 256), (8, 512)</p>
<p>FOR j (cid:197) 0 TO KL-1</p>
<p>i (cid:197) j * 64</p>
<p>IF k1[j] OR *no writemask* THEN</p>
<p>IF (EVEX.b == 1) AND (SRC2 *is memory*)</p>
<p>THEN DEST[i+63:i] (cid:197) RangeDP (SRC1[i+63:i], SRC2[63:0], CmpOpCtl[1:0], SignSelCtl[1:0]);</p>
<p>ELSE DEST[i+63:i] (cid:197) RangeDP (SRC1[i+63:i], SRC2[i+63:i], DAZ, CmpOpCtl[1:0], SignSelCtl[1:0]);</p>
<p>FI;</p>
<p>ELSE</p>
<p>IF *merging-masking*</p>
<p>; merging-masking</p>
<p>THEN *DEST[i+63:i] remains unchanged*</p>
<p>ELSE</p>
<p>; zeroing-masking</p>
<p>DEST[i+63:i] = 0</p>
<p>FI;</p>
<p>FI;</p>
<p>ENDFOR;</p>
<p>DEST[MAX_VL-1:VL] (cid:197) 0</p>
<p>The following example describes a common usage of this instruction for checking that the input operand is bounded between ±1023.</p>
<p>VRANGEPD zmm_dst, zmm_src, zmm_1023, 02h;</p>
<p>Where:</p>
<p>zmm_dst is the destination operand. zmm_src is the input operand to compare against ±1023 (this is SRC1). zmm_1023 is the reference operand, contains the value of 1023 (and this is SRC2). IMM=02(imm8[1:0]='10) selects the Min Absolute value operation with selection of SRC1.sign.</p>
<p>In case |zmm_src| &lt; 1023 (i.e. SRC1 is smaller than 1023 in magnitude), then its value will be written into zmm_dst. Otherwise, the value stored in zmm_dst will get the value of 1023 (received on zmm_1023, which is SRC2). However, the sign control (imm8[3:2]='00) instructs to select the sign of SRC1 received from zmm_src. So, even in the case of |zmm_src| ≥ 1023, the selected sign of SRC1 is kept. Thus, if zmm_src &lt; -1023, the result of VRANGEPD will be the minimal value of -1023 while if zmm_src &gt; +1023, the result of VRANGE will be the maximal value of +1023.</p>
<p><strong>Intel C/C++ Compiler Intrinsic Equivalent</strong></p>
<p>VRANGEPD __m512d _mm512_range_pd ( __m512d a, __m512d b, int imm); VRANGEPD __m512d _mm512_range_round_pd ( __m512d a, __m512d b, int imm, int sae); VRANGEPD __m512d _mm512_mask_range_pd (__m512 ds, __mmask8 k, __m512d a, __m512d b, int imm); VRANGEPD __m512d _mm512_mask_range_round_pd (__m512d s, __mmask8 k, __m512d a, __m512d b, int imm, int sae); VRANGEPD __m512d _mm512_maskz_range_pd ( __mmask8 k, __m512d a, __m512d b, int imm); VRANGEPD __m512d _mm512_maskz_range_round_pd ( __mmask8 k, __m512d a, __m512d b, int imm, int sae); VRANGEPD __m256d _mm256_range_pd ( __m256d a, __m256d b, int imm); VRANGEPD __m256d _mm256_mask_range_pd (__m256d s, __mmask8 k, __m256d a, __m256d b, int imm); VRANGEPD __m256d _mm256_maskz_range_pd ( __mmask8 k, __m256d a, __m256d b, int imm); VRANGEPD __m128d _mm_range_pd ( __m128 a, __m128d b, int imm); VRANGEPD __m128d _mm_mask_range_pd (__m128 s, __mmask8 k, __m128d a, __m128d b, int imm); VRANGEPD __m128d _mm_maskz_range_pd ( __mmask8 k, __m128d a, __m128d b, int imm);</p>
<p><strong>SIMD Floating-Point Exceptions</strong></p>
<p>Invalid, Denormal</p>
<p><strong>Other Exceptions</strong></p>
<p>See Exceptions Type E2.</p></body></html>